package config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class WebMvcConfiguration extends WebMvcConfigurationSupport {
	
	@Value("${file.basePath}")
	private String basePath;
	@Override
	protected void addResourceHandlers(ResourceHandlerRegistry registry) {
	    String os = System.getProperty("os.name");

	    //如果是Windows系统
	    if (os.toLowerCase().startsWith("win")) {
	        registry.addResourceHandler("/fileUpload/**")
	                // /app_file/**表示在磁盘filePathWindow目录下的所有资源会被解析为以下的路径
	                .addResourceLocations("file:" + basePath);
	    } else {  //linux 和mac
	        registry.addResourceHandler("/images/**")
	                .addResourceLocations("file:" + "") ;
	    }
	    registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/").setCachePeriod(0);
	    super.addResourceHandlers(registry);
	}
}
